using System;
using Castle.Core.Configuration;

namespace Mistral.Serialization
{
	public class CastleAdapter
	{
		public IConfiguration Convert( IObjectDefinition objectDefinition )
		{
			IConfiguration configuration = new MutableConfiguration( "component" );
			Type type = Type.GetType(objectDefinition.Type);
			configuration.Attributes.Add( "id", "a" );
			configuration.Attributes.Add( "type", type.AssemblyQualifiedName );
			IConfiguration parameters = new MutableConfiguration( "parameters" );
			configuration.Children.Add( parameters );
			foreach ( var propertyValue in objectDefinition.PropertyValues )
			{
				string value = System.Convert.ToString( propertyValue.Value );
				parameters.Children.Add( new MutableConfiguration( propertyValue.Name, value ) );
			}

			return configuration;
		}
	}
}